449D - Jzzhu and Numbers - CodeForces Solution


bitmasks combinatorics dp *2400

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
using INT = long long;
const int NN = 1e6 + 100;
int dp[NN][21],a[NN],p[NN];
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
#endif
	  int n,mod=1000000007;
	  cin>>n;
	  for(int i=1;i<=n;i++) scanf("%d",a+i),dp[a[i]][0]++;
	  for(int j=1;j<=20;j++){
	  	for(int i=0;i<NN;i++){
			dp[i][j]=dp[i][j-1];
	  		if(i&(1<<j-1)) continue;
	  		if(i+(1<<j-1)<NN) dp[i][j]+=dp[i+(1<<j-1)][j-1];
		  }
	  }
	  p[0]=1;
	  for(int i=1;i<NN;i++) p[i]=p[i-1]*2%mod;
	  int ans=0;
	  for(int i=0;i<NN;i++){
	  	int id=p[dp[i][20]]-1;
	  	int k=__builtin_popcount(i);
	  	if((k%2)) id=mod-id;
	  	ans=(ans+id)%mod;
	  }
	  printf("%d\n",ans);
	  
	return 0;
}


Comments

Submit
0 Comments
More Questions

281A - Word Capitalization
1646A - Square Counting
266A - Stones on the Table
61A - Ultra-Fast Mathematician
148A - Insomnia cure
1650A - Deletions of Two Adjacent Letters
1512A - Spy Detected
282A - Bit++
69A - Young Physicist
1651A - Playoff
734A - Anton and Danik
1300B - Assigning to Classes
1647A - Madoka and Math Dad
710A - King Moves
1131A - Sea Battle
118A - String Task
236A - Boy or Girl
271A - Beautiful Year
520B - Two Buttons
231A - Team
479C - Exams
1030A - In Search of an Easy Problem
158A - Next Round
71A - Way Too Long Words
160A - Twins
1A - Theatre Square
1614B - Divan and a New Project
791A - Bear and Big Brother
1452A - Robot Program
344A - Magnets